set(TARGET base)

set(HEADERS
BaseExport.h
BaseObject.h
)
set(SOURCES BaseObject.cpp)

add_library(${TARGET} SHARED ${HEADERS} ${SOURCES})
add_library(EasyBrep::Base ALIAS ${TARGET})

target_compile_definitions(${TARGET} PRIVATE BASE_BUILD_DLL)

target_include_directories(${TARGET} INTERFACE 
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
target_compile_features(${TARGET} PRIVATE cxx_std_20)

set_target_properties(${TARGET} PROPERTIES 
PUBLIC_HEADER "${HEADERS}"
)


include(CMakePackageConfigHelpers)

write_basic_package_version_file(
    "${CMAKE_CURRENT_BINARY_DIR}/baseConfigVersion.cmake"
    VERSION ${PROJECT_VERSION}
    COMPATIBILITY SameMajorVersion
)

set(INCLUDE_INSTALL_DIR include/base)
set(LIB_INSTALL_DIR lib)

configure_package_config_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/BaseConfig.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/BaseConfig.cmake"
    INSTALL_DESTINATION lib/cmake/base
    PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR
)

install(TARGETS ${TARGET}
    EXPORT BaseTargets
    RUNTIME DESTINATION bin
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
    PUBLIC_HEADER DESTINATION include/base
)

install(EXPORT BaseTargets
    FILE BaseTargets.cmake
    NAMESPACE easybrep::
    DESTINATION lib/cmake/base
)

install(FILES
    "${CMAKE_CURRENT_BINARY_DIR}/BaseConfig.cmake"
    "${CMAKE_CURRENT_BINARY_DIR}/BaseConfigVersion.cmake"
    DESTINATION lib/cmake/base
)

export(EXPORT BaseTargets
    FILE "${CMAKE_CURRENT_BINARY_DIR}/BaseTargets.cmake"
    NAMESPACE easybrep::
)